<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Provider;

use App\Entity\User;

class UserManager
{
    protected array $users = [];

    protected array $fdUser = [];

    public function setUser(User $user)
    {
        $this->users[$user->getUserId()] = $user;
        $this->fdUser[$user->getFd()] = $user;
    }

    public function getUser(int $userId): User
    {
        return $this->users[$userId];
    }

    public function hasUser(int $userId)
    {
        return isset($this->users[$userId]);
    }

    public function getUserFromFd(int $fd): User
    {
        return $this->fdUser[$fd];
    }

    public function removeFd(int $fd)
    {
        unset($this->fdUser[$fd]);
    }

    public function removeUser(int $userId)
    {
        unset($this->users[$userId]);
    }
}
